﻿function Get-BinariesRepositoryManager
{
    [cmdletbinding(DefaultParameterSetName="none")]
    Param( 
        [Parameter(Mandatory=$true,ValueFromPipeline=$false)]
        [String]$UniqueKey,

        [Parameter(Mandatory=$true,ValueFromPipeline=$false)]
        [String]$LocalPath,

        [Parameter(Mandatory=$true,ValueFromPipeline=$false)]
        [String]$RemotePath
    )
    Begin
    {
        $watch = [system.diagnostics.stopwatch]::StartNew() 
        write-verbose "Start Get-BinariesRepositoryManager identified by '$UniqueKey' with localPath '$LocalPath' and RemotePath '$RemotePath'"
    }
    End
    {
        write-verbose "End Get-BinariesRepositoryManager identified by '$UniqueKey' with localPath '$LocalPath' and RemotePath '$RemotePath'"
        $watch.Stop();
        Write-Verbose "Function duration : $($watch.Elapsed)"
    }

    Process
    {

        $BinariesRepositoryManager = new-Object PSObject -Property @{
                                                                    UniqueKey=$UniqueKey
                                                                    LocalPath=$LocalPath
                                                                    RemotePath=$RemotePath
                                                                    }



        $BinariesRepositoryManager | Add-Member -MemberType ScriptMethod -Name GetVirtualProductPath -Value {
           .{
                param (	
                    [Parameter(Mandatory=$true)]
                    [ValidateNotNullOrEmpty()]
	                [PSObject]$Product
                )
                Process
                {
                    $path = [System.IO.Path]::Combine($path, $Product.companyName)
                    $path = [System.IO.Path]::Combine($path, $Product.productName)
                    $path = [System.IO.Path]::Combine($path, $Product.version)
                    $path = [System.IO.Path]::Combine($path, $Product.packageName)
                    Write-Output $path

                }
            } @args 
        }


        $BinariesRepositoryManager | Add-Member -MemberType ScriptMethod -Name GetLocalProductPath -Value {
           .{
                param (	
                    [Parameter(Mandatory=$true)]
                    [ValidateNotNullOrEmpty()]
	                [PSObject]$Product
                )
                Process
                {
                    [System.IO.Path]::Combine($this.LocalPath, $this.GetVirtualProductPath($Product))
                }
            } @args 
        }

        $BinariesRepositoryManager | Add-Member -MemberType ScriptMethod -Name GetRemoteProductPath -Value {
           .{
                param (	
                    [Parameter(Mandatory=$true)]
                    [ValidateNotNullOrEmpty()]
	                [PSObject]$Product
                )
                Process
                {
                    [System.IO.Path]::Combine($this.RemotePath, $this.GetVirtualProductPath($Product))
                }
            } @args 
        }



        Write-Output $BinariesRepositoryManager
    }
}

